/* Y o u r   D e s c r i p t i o n                       */
/*                            AppBuilder Photon Code Lib */
/*                                         Version 1.13X */

/* Standard headers */
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>

/* Toolkit headers */
#include <Ph.h>
#include <Pt.h>
#include <Ap.h>

/* Local headers */
#include "ph_ewind.h"
#include "abimport.h"
#include "proto.h"

extern lsrDispWindow dispWind;

int resizeWin(PtWidget_t *widget, ApInfo_t *apinfo, PtCallbackInfo_t *cbinfo)
{

	/* eliminate 'unreferenced' warnings */
	widget = widget, apinfo = apinfo, cbinfo = cbinfo;

	/* get the interior extent of the eye wind widget */
	PtBasicWidgetCanvas((PtWidget_t *)ABW_displayWindow, &dispWind.canvas);
	dispWind.area.pos.x  = dispWind.canvas.ul.x;
	dispWind.area.pos.y  = dispWind.canvas.ul.y;
	dispWind.area.size.w = dispWind.canvas.lr.x - dispWind.canvas.ul.x;
	dispWind.area.size.h = dispWind.canvas.lr.y - dispWind.canvas.ul.y;

	/* This seems to be necessary to get the left scale redrawn
	 * when only the width of the window is changed.
	 */
	PtDamageWidget(ABW_leftScale);

	return(Pt_CONTINUE);
}

int winExpose( PtWidget_t *widget, ApInfo_t *apinfo, PtCallbackInfo_t *cbinfo )
{
	PhWindowEvent_t *winEvent;
	PtArg_t args[2];
	static int iconified;

	/* eliminate 'unreferenced' warnings */
	widget = widget, apinfo = apinfo, cbinfo = cbinfo;

	winEvent = (PhWindowEvent_t *)cbinfo->cbdata;

	/* check to see which type event evoked this callback */
	if((winEvent->event_f == Ph_WM_FOCUS) || 
	   (winEvent->event_f == Ph_WM_TOFRONT)) {
		/* damage all widgets to force redraws */
		PtDamageWidget(ABW_leftScale);
		PtDamageWidget(ABW_bottomScale);
		PtDamageWidget(ABW_eyeWndControlPane);
		PtDamageWidget(ABW_curs0Btn);
		PtDamageWidget(ABW_curs1Btn);
		PtDamageWidget(ABW_curs2Btn);
		PtDamageWidget(ABW_curs3Btn);
		PtDamageWidget(ABW_curs4Btn);
		PtDamageWidget(ABW_curs5Btn);
		PtDamageWidget(ABW_curs6Btn);
		PtDamageWidget(ABW_curs7Btn);
		PtDamageWidget(ABW_wnd0Btn);
		PtDamageWidget(ABW_wnd1Btn);
		PtDamageWidget(ABW_wnd2Btn);
		PtDamageWidget(ABW_wnd3Btn);
		PtDamageWidget(ABW_wnd4Btn);
		PtDamageWidget(ABW_wnd5Btn);
		PtDamageWidget(ABW_wnd6Btn);
		PtDamageWidget(ABW_wnd7Btn);
		PtDamageWidget(ABW_eyeOffsetGroupLabel);
		PtDamageWidget(ABW_eyeHorizOffsetLabel);
		PtDamageWidget(ABW_eyeHorizOffset);
		PtDamageWidget(ABW_eyeVertOffsetLabel);
		PtDamageWidget(ABW_eyeVertOffset);
		PtDamageWidget(ABW_otherEyeOffsetGroupLabel);
		PtDamageWidget(ABW_oEyeHorizOffsetLabel);
		PtDamageWidget(ABW_oEyeHorizOffset);
		PtDamageWidget(ABW_oEyeVertOffsetLabel);
		PtDamageWidget(ABW_oEyeVertOffset);
	}
	else if(winEvent->event_f == Ph_WM_CLOSE) {
		/* shut off window display processing by msec_clock */
		i_b->d_flags &= ~D_WIND;
		release_(&myptp->p_sem);
		myptp->p_state |= P_EXIT_ST;
		myptp->p_id = 0;
		exit(EXIT_SUCCESS);
	}
	else if(winEvent->event_f == Ph_WM_ICON && !iconified) {
		iconified = 1;

		/* shut off raster processing */
		PtSetArg(&args[0], Pt_ARG_TIMER_INITIAL, 0, 0);
		PtSetArg(&args[1], Pt_ARG_TIMER_REPEAT, 0, 0);
		PtSetResources(ABW_wndTimer, 2, args);
	}
	else if(winEvent->event_f == Ph_WM_RESTORE) {
		iconified = 0;

		/* turn on raster processing  */
		PtSetArg(&args[0], Pt_ARG_TIMER_INITIAL, 16, 0);
		PtSetArg(&args[1], Pt_ARG_TIMER_REPEAT, 16, 0);
		PtSetResources(ABW_wndTimer, 2, args);
	}

	return( Pt_CONTINUE );
}

